/*
 * Location.cpp
 *
 *  Created on: Mar 7, 2011
 *      Author: Michael Ziminsky
 */

#include "Location.h"
#include "ChessBoard.h"

namespace model
{
	Location::Location(char c, int r) :
		col(toupper(c)), row(r)
	{
	}

	Location::Location(const Location & l) :
		col(l.col), row(l.row)
	{
	}

	std::size_t hash_value(const Location & l)
	{
		std::size_t seed = 0;
		boost::hash_combine(seed, l.col);
		boost::hash_combine(seed, l.row);

		return seed;
	}

	std::ostream& operator <<(std::ostream& out, const Location& l)
	{
		return out << l.col << l.row;
	}

	bool Location::operator==(const Location & l) const
	{
		return col == l.col && row == l.row;
	}

	bool Location::operator !=(const Location& l) const
	{
		return !(*this == l);
	}

	bool Location::operator <(const Location& l) const
	{
		int r1 = ChessBoard::SIZE + 1 - row;
		int r2 = ChessBoard::SIZE + 1 - l.row;
		return (l.col * r2) < (col * r1);
	}

	bool Location::operator >(const Location& l) const
	{
		return *this < l;
	}

	bool Location::operator <=(const Location& l) const
	{
		return l < *this || *this == l;
	}

	bool Location::operator >=(const Location& l) const
	{
		return l > *this || *this == l;
	}
}